package org.ran.demo.http.socket;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

import org.ran.demo.http.util.StreamUtil;
/**
 * echo 客户端
 * @author caoran
 *
 */
public class TextClientDemo {
    public static void main(String[] args) throws Exception{
        try(Socket socket = new Socket();){
            socket.connect(new InetSocketAddress("127.0.0.1", 8080));
            InputStream in = socket.getInputStream();
            OutputStream out = socket.getOutputStream();
            int counter=0;
            while (counter<3) {
                String read = StreamUtil.readLine(System.in);
                StreamUtil.writeLine(read, out);
                String res = StreamUtil.readLine(in);
                System.out.println("echo message: "+res);
                counter++;
            }
        }
    }
}
